package cn.tedu._03vehicle.base.interceptors;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("1.preHandle方法执行");
        HttpSession session = request.getSession();
        if (session.getAttribute("user") != null) {
            return true;
        }
        response.sendRedirect("/login.html");
//        return HandlerInterceptor.super.preHandle(request, response, handler);
        return false;
    }

}
